﻿namespace ExamV5.ManagSys
{
    using ExamV5;
    using System;
    using System.Configuration;
    using System.Data;
    using System.Data.SqlClient;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;

    public class FrmMemberLevel : Page
    {
        protected Button butAdd;
        protected GridView DataGridInfo;
        protected DropDownList DDLRemoveType;
        protected HtmlForm form1;
        private HttpCookie httpCookie_0 = null;
        private HttpCookie httpCookie_1 = null;
        private HttpCookie httpCookie_2 = null;
        private HttpCookie httpCookie_3 = null;
        protected Label labRescordCount;
        protected LinkButton LBFirstPage;
        protected LinkButton LBLastPage;
        protected LinkButton LBNextPage;
        protected LinkButton LBPrevPage;
        private PublicFun publicFun_0 = new PublicFun();
        protected ScriptManager SM;
        protected TextBox txtLevelFen;
        protected TextBox txtLevelName;
        protected TextBox txtRemoveFen;
        protected UpdatePanel UPPart;

        protected void butQuery_Click(object sender, EventArgs e)
        {
            if (Convert.ToInt32(ConfigurationManager.ConnectionStrings["OnlineNum"].ConnectionString) != 0x3a)
            {
                this.publicFun_0.ExecuteSql("Insert into MemberLevel(LevelName,LevelFen,LevelRemove,RemoveValue) values('" + this.publicFun_0.CheckString(this.txtLevelName.Text) + "'," + this.txtLevelFen.Text.Trim() + ",'" + this.DDLRemoveType.SelectedItem.Value + "'," + this.txtRemoveFen.Text.Trim() + ")");
                this.method_0();
                this.txtLevelName.Text = "";
                this.txtLevelFen.Text = "";
                this.DDLRemoveType.SelectedIndex = -1;
                this.DDLRemoveType.SelectedIndex = 0;
                this.txtRemoveFen.Text = "";
            }
            else
            {
                ScriptManager.RegisterStartupScript(this.UPPart, this.Page.GetType(), "BTHB", "alert('该版本为特惠版，此功能未开放！')", true);
            }
        }

        protected void DataGridInfo_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            this.DataGridInfo.PageIndex = e.NewPageIndex;
            this.method_0();
        }

        protected void DataGridInfo_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
        {
            this.DataGridInfo.EditIndex = -1;
            this.method_0();
        }

        protected void DataGridInfo_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.DataItemIndex == -1)
            {
                this.DataGridInfo.Attributes.Add("oldValue", "#FFFFFF");
                this.DataGridInfo.Attributes.Add("singleValue", "#FFFFFF");
            }
            else
            {
                e.Row.Attributes.Add("onmouseover", "this.bgColor='#F6F5F5'");
                if ((e.Row.DataItemIndex % 2) != 0)
                {
                    e.Row.Attributes.Add("bgcolor", "#FFFFFF");
                    e.Row.Attributes.Add("onmouseout", "this.bgColor=document.getElementById('DataGridInfo').getAttribute('oldValue')");
                }
                else
                {
                    e.Row.Attributes.Add("bgcolor", "#FFFFFF");
                    e.Row.Attributes.Add("onmouseout", "this.bgColor=document.getElementById('DataGridInfo').getAttribute('singleValue')");
                }
            }
            if ((e.Row.RowIndex != -1) && !((e.Row.RowState != DataControlRowState.Edit) ? (e.Row.RowState != (DataControlRowState.Edit | DataControlRowState.Alternate)) : false))
            {
                TextBox box = (TextBox) e.Row.Cells[0].Controls[0];
                TextBox box2 = (TextBox) e.Row.Cells[1].Controls[0];
                DropDownList list = (DropDownList) e.Row.Cells[2].FindControl("DDLLevelRemove");
                TextBox box3 = (TextBox) e.Row.Cells[3].Controls[0];
                box.Width = 200;
                box.CssClass = "text";
                box.Height = 0x13;
                box2.Width = 60;
                box2.CssClass = "text";
                box2.Height = 0x13;
                box3.Width = 60;
                box3.CssClass = "text";
                box3.Height = 0x13;
                list.SelectedIndex = -1;
                list.Items.FindByValue(this.DataGridInfo.DataKeys[e.Row.RowIndex]["RemoveType"].ToString()).Selected = true;
            }
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                LinkButton button = (LinkButton) e.Row.Cells[5].FindControl("LBDel");
                button.Attributes.Add("onclick", "javascript:{if(confirm('确定要会员级别[" + e.Row.Cells[0].Text + "]吗？')==false) return false;}");
            }
            if (e.Row.RowType == DataControlRowType.Header)
            {
                string str;
                if (this.ViewState["SortType"].ToString() == " Desc")
                {
                    str = this.ViewState["SortFiled"].ToString();
                    switch (str)
                    {
                        case null:
                            goto Label_04A7;

                        case "LevelName":
                            e.Row.Cells[0].Controls.Add(new LiteralControl("↑"));
                            return;
                    }
                    if (!(str == "LevelFen"))
                    {
                        if (!(str == "RemoveValue"))
                        {
                            goto Label_04A7;
                        }
                        e.Row.Cells[3].Controls.Add(new LiteralControl("↑"));
                    }
                    else
                    {
                        e.Row.Cells[1].Controls.Add(new LiteralControl("↑"));
                    }
                    return;
                }
                str = this.ViewState["SortFiled"].ToString();
                switch (str)
                {
                    case null:
                        goto Label_03C5;

                    case "LevelName":
                        e.Row.Cells[0].Controls.Add(new LiteralControl("↓"));
                        return;
                }
                if (!(str == "LevelFen"))
                {
                    if (!(str == "RemoveValue"))
                    {
                        goto Label_03C5;
                    }
                    e.Row.Cells[3].Controls.Add(new LiteralControl("↓"));
                }
                else
                {
                    e.Row.Cells[1].Controls.Add(new LiteralControl("↓"));
                }
            }
            return;
        Label_03C5:
            e.Row.Cells[0].Controls.Add(new LiteralControl("↓"));
            return;
        Label_04A7:
            e.Row.Cells[0].Controls.Add(new LiteralControl("↑"));
        }

        protected void DataGridInfo_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            string str = this.DataGridInfo.DataKeys[e.RowIndex]["ID"].ToString();
            if (str.Trim() != "1")
            {
                if (!(this.publicFun_0.GetValues("select ID from UserInfo where UserMember='" + str + "'", "ID") == ""))
                {
                    ScriptManager.RegisterStartupScript(this.UPPart, this.Page.GetType(), "BPower", "alert('此会员级别中还存在会员数据,无法删除！')", true);
                }
                else
                {
                    this.publicFun_0.ExecuteSql("delete MemberLevel where ID='" + str + "';insert into SysLogInfo(LogDisp,EditUser,EditUserCode) values('对会员级别进行删除操作！','" + this.httpCookie_1.Value + "','" + this.httpCookie_0.Value + "')");
                }
            }
            else
            {
                ScriptManager.RegisterStartupScript(this.UPPart, this.Page.GetType(), "BPower", "alert('系统默认数据不允许删除,但可以修改！')", true);
            }
            this.method_0();
        }

        protected void DataGridInfo_RowEditing(object sender, GridViewEditEventArgs e)
        {
            this.DataGridInfo.EditIndex = e.NewEditIndex;
            this.method_0();
        }

        protected void DataGridInfo_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            try
            {
                int num = 0;
                int num2 = 0;
                TextBox box = (TextBox) this.DataGridInfo.Rows[e.RowIndex].Cells[0].Controls[0];
                TextBox box2 = (TextBox) this.DataGridInfo.Rows[e.RowIndex].Cells[1].Controls[0];
                DropDownList list = (DropDownList) this.DataGridInfo.Rows[e.RowIndex].Cells[2].FindControl("DDLLevelRemove");
                TextBox box3 = (TextBox) this.DataGridInfo.Rows[e.RowIndex].Cells[3].Controls[0];
                num = Convert.ToInt32(box2.Text);
                num2 = Convert.ToInt32(box3.Text);
                this.publicFun_0.ExecuteSql(string.Concat(new object[] { "update MemberLevel set LevelName='", box.Text, "',LevelFen='", num, "',LevelRemove='", list.SelectedItem.Value, "',RemoveValue='", num2, "' where ID='", this.DataGridInfo.DataKeys[e.RowIndex]["ID"].ToString(), "';insert into SysLogInfo(LogDisp,EditUser,EditUserCode) values('修改会别级别操作！','", this.httpCookie_1.Value, "','", this.httpCookie_0.Value, "')" }));
                this.DataGridInfo.EditIndex = -1;
                this.method_0();
            }
            catch
            {
            }
        }

        protected void DataGridInfo_Sorting(object sender, GridViewSortEventArgs e)
        {
            string sortExpression = e.SortExpression;
            if (!(this.ViewState["SortFiled"].ToString() == sortExpression))
            {
                this.ViewState["SortFiled"] = e.SortExpression;
            }
            else if (this.ViewState["SortType"].ToString() == " Desc")
            {
                this.ViewState["SortType"] = " ASC";
            }
            else
            {
                this.ViewState["SortType"] = " Desc";
            }
            this.method_0();
        }

        protected void LBFirstPage_Click(object sender, EventArgs e)
        {
            this.DataGridInfo.PageIndex = 0;
            this.method_0();
        }

        protected void LBLastPage_Click(object sender, EventArgs e)
        {
            if (this.DataGridInfo.PageCount > 0)
            {
                this.DataGridInfo.PageIndex = this.DataGridInfo.PageCount - 1;
                this.method_0();
            }
        }

        protected void LBNextPage_Click(object sender, EventArgs e)
        {
            if (this.DataGridInfo.PageIndex < (this.DataGridInfo.PageCount - 1))
            {
                this.DataGridInfo.PageIndex++;
                this.method_0();
            }
        }

        protected void LBPrevPage_Click(object sender, EventArgs e)
        {
            if (this.DataGridInfo.PageIndex > 0)
            {
                this.DataGridInfo.PageIndex--;
                this.method_0();
            }
        }

        private void method_0()
        {
            string selectCommandText = "";
            if (this.ViewState["UserPower"].ToString() == "Y")
            {
                selectCommandText = "select *,LevelRemove as RemoveType,RemoveName=case LevelRemove when 'A' then '不做任何扣除' when 'B' then '按考试次数扣除' when 'C' then '按指定时间清除（天）' when 'D' then '按试卷定义积分扣除'  end from MemberLevel ";
            }
            else
            {
                selectCommandText = "select *,LevelRemove as RemoveType,RemoveName=case LevelRemove when 'A' then '不做任何扣除' when 'B' then '按考试次数扣除' when 'C' then '按指定时间清除（天）' when 'D' then '按试卷定义积分扣除'  end from MemberLevel where ID=0 ";
                ScriptManager.RegisterStartupScript(this.UPPart, this.Page.GetType(), "BPower", "alert('用户管理权限未开放！')", true);
            }
            selectCommandText = selectCommandText + "  order by " + this.ViewState["SortFiled"].ToString() + this.ViewState["SortType"].ToString();
            SqlConnection selectConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["Conn"].ConnectionString);
            SqlDataAdapter adapter = new SqlDataAdapter(selectCommandText, selectConnection);
            DataSet dataSet = new DataSet();
            adapter.Fill(dataSet, "DataInfo");
            this.DataGridInfo.DataSource = dataSet.Tables["DataInfo"].DefaultView;
            this.DataGridInfo.DataBind();
            this.labRescordCount.Text = "总共&nbsp;<font color='#0000C0'><b>" + dataSet.Tables["DataInfo"].Rows.Count.ToString() + "</b></font>&nbsp;条记录&nbsp;<font color='#0000C0'><b>" + Convert.ToString((int) (this.DataGridInfo.PageIndex + 1)) + "/" + this.DataGridInfo.PageCount.ToString() + "</b></font>&nbsp;页&nbsp;";
            adapter.Dispose();
            selectConnection.Close();
            selectConnection.Dispose();
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            this.httpCookie_0 = new HttpCookie("ExamUserCode");
            this.httpCookie_0 = base.Request.Cookies["ExamUserCode"];
            this.httpCookie_1 = new HttpCookie("ExamUserName");
            this.httpCookie_1 = base.Request.Cookies["ExamUserName"];
            this.httpCookie_2 = new HttpCookie("ExamUserLevel");
            this.httpCookie_2 = base.Request.Cookies["ExamUserLevel"];
            this.httpCookie_3 = new HttpCookie("ExamDeptID");
            this.httpCookie_3 = base.Request.Cookies["ExamDeptID"];
            if ((this.httpCookie_0 != null) ? !(this.httpCookie_0.Value == "") : false)
            {
                base.Response.Cache.SetCacheability(HttpCacheability.NoCache);
                base.Response.Cache.SetNoStore();
                this.httpCookie_0.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_0.Value));
                this.httpCookie_1.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_1.Value));
                this.httpCookie_2.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_2.Value));
                this.httpCookie_3.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_3.Value));
                if (Convert.ToInt32(ConfigurationManager.ConnectionStrings["OnlineNum"].ConnectionString) != 0x3a)
                {
                    if (!base.IsPostBack)
                    {
                        if (this.publicFun_0.ReturnPaperData() != "Yes")
                        {
                            ScriptManager.RegisterStartupScript(this.UPPart, this.Page.GetType(), "BCheck", "alert('此版本暂未授权,请拔打(0)13870606104手机号进行授权！')", true);
                        }
                        else
                        {
                            this.ViewState["UserPower"] = this.publicFun_0.GetValues("select ManagUser from UserPower where UserCode='" + this.httpCookie_0.Value + "'", "ManagUser");
                            this.ViewState["SortFiled"] = "ID";
                            this.ViewState["SortType"] = " Desc";
                            this.method_0();
                        }
                    }
                }
                else
                {
                    ScriptManager.RegisterStartupScript(this.UPPart, this.Page.GetType(), "BTHB", "alert('该版本为特惠版，此功能未开放！')", true);
                }
            }
            else
            {
                base.Response.Write("<script language=javascript>top.location.href='../Index.htm';self.close();</script>");
            }
        }
    }
}

